<?php

namespace UF\AccountBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * UF\AccountBundle\Entity\account
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Account implements UserInterface {
	/**
	 * @var integer $id
	 *
	 * @ORM\Column(name="id", type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	private $id;

	/**
	 * @var string $username
	 *
	 * @ORM\Column(name="username", type="string", length=255, unique=true)
	 */
	private $username;

	/**
	 * @var text $description
	 *
	 * @ORM\Column(name="description", type="string", length=255)
	 */
	private $description;
	
	/**
	 * @var string $password
	 *
	 * @ORM\Column(name="password", type="string", length=255)
	 */
	private $password;

	/**
	 * @var string $roles
	 *
	 * @ORM\Column(name="roles", type="string", length=255)
	 */
	private $role;

	/**
	 * Get id
	 *
	 * @return integer 
	 */
	
	/**
	* @ORM\OneToMany(targetEntity="Guest", mappedBy="account", cascade={"all"})
	*/
	private $guests;
	
	public function getId() {return $this->id;}
	public function setUsername($username) {$this->username = $username;}
	public function getUsername() {return $this->username;}
	public function setDescription($description) {$this->description = $description;}
	public function getDescription() {return $this->description;}
	public function setPassword($password) {$this->password = $password;}
	public function getPassword() {return $this->password;}
	public function getRoles() {return array($this->role);}
	public function getRole(){return $this->role;}
	public function setRole($role) {$this->role = $role;}
	public function getSalt() {}
	public function eraseCredentials() {}
	public function equals(UserInterface $user) {}	
	public function addGuest(Guest $guest){$this->guests[] = $guest;}
	public function getGuests(){return $this->guests;}
	
	public static function genPassword() {
		$tpass=array();
		$id=0;
		$taille=8;
		// récupération des chiffres et lettre
		for($i=48;$i<58;$i++) $tpass[$id++]=chr($i);
		for($i=65;$i<91;$i++) $tpass[$id++]=chr($i);
		for($i=97;$i<123;$i++) $tpass[$id++]=chr($i);
		$passwd="";
		for($i=0;$i<$taille;$i++) {
			$passwd.=$tpass[rand(0,$id-1)];
		}
		return $passwd;
	}

}
